#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int N = 1010;
int f[N][N];
string s1, s2;
int main()
{
	int ans = 0;
	cin >> s1 >> s2;
	s1 = " " + s1;
	s2 = " " + s2;
	for (int i = 1; i <= s1.size() - 1; i++) {
		for (int j = 1; j <= s2.size() - 1; j++) {
			if (s1[i] == s2[j]) {
				f[i][j] = f[i - 1][j - 1] + 1;
			}
			ans = max(ans, f[i][j]);
		}
	}
	cout << ans << endl;
	for (int i = 1; i <= s1.size() - 1; i++) {
		for (int j = 1; j <= s2.size() - 1; j++) {
			cout << f[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}